package com.zxl.app.service;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.zxl.common.mapper.SysGoodsMapper;
import com.zxl.common.model.query.goods.SearchQuery;
import com.zxl.common.model.vo.goods.SearchGoodsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/1
 */
@Service
public class GoodsService {
    @Resource
    private SysGoodsMapper sysGoodsMapper;

    public List<SearchGoodsVo> search(SearchQuery query) {
        if (query.getGoodsCategoryId() != null){
            if (query.getGoodsCategoryId().equals("0")){
                query.setGoodsCategoryId(null);
            }
        }
        if (StrUtil.isBlank(query.getField())){
            query.setField("create_time");
        }
        if (StrUtil.isBlank(query.getOrderBy())){
         query.setOrderBy("desc");
        }
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        List<SearchGoodsVo> goodsVoList = sysGoodsMapper.search(query);
        return goodsVoList;
    }



}
